package com.aios.dao;

import com.aios.entity.SwitchPanel;
import com.aios.entity.SystemUser;
import com.aios.entity.SystemUserExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

	public interface SystemUserMapper {
	   
	int updateByPrimaryKey(SystemUser record);

	int countByExample(SystemUserExample example);

    int deleteByExample(SystemUserExample example);

    int deleteByPrimaryKey(String id);

    int insert(SystemUser record);

    int insertSelective(SystemUser record);

    List<SystemUser> selectByExample(SystemUserExample example);

    SystemUser selectByPrimaryKey(String id);
    
    @Select("SELECT * FROM system_user WHERE ID = #{id} AND STATUS=#{status}")
   	@ResultMap(value="MiniResultMap")
    SystemUser selectActiveUserByPrimaryKey(@Param("id") String id,@Param("status") int status);

    int updateByExampleSelective(@Param("record") SystemUser record, @Param("example") SystemUserExample example);

    int updateByExample(@Param("record") SystemUser record, @Param("example") SystemUserExample example);

    int updateByPrimaryKeySelective(SystemUser record);
    
    
    @Select("SELECT * FROM system_user WHERE EMAIL = #{username} AND USER_PASSWORD=#{password} AND STATUS=0")
   	@ResultMap(value="MiniResultMap")
   	List<SystemUser> findByEmailAndPassword(
   			@Param("username") String username,
   			@Param("password") String password);
    
    @Select("SELECT * FROM system_user WHERE STATUS = #{status} ORDER BY SORT_ORDER")
   	@ResultMap(value="MiniResultMap")
   	List<SystemUser> findAllByStatus(@Param("status") Integer status);
    
    @Select("SELECT * FROM system_user WHERE EMAIL = #{email}")
   	@ResultMap(value="MiniResultMap")
   	List<SystemUser> findByEmailAddress(@Param("email") String email);
   
   	@Select("SELECT COUNT(*) FROM system_user WHERE STATUS = #{status}")
  	Integer countAllByStatus(@Param("status") Integer status);
   	
   	@Select("SELECT * FROM system_user WHERE STATUS = #{status} ORDER BY SORT_ORDER LIMIT #{start}, #{size}")
    @ResultMap(value="MiniResultMap")
    List<SystemUser> findListPaginated(@Param("status") Integer status, 
			@Param("start") Integer start, @Param("size") Integer size);
   	
 	@Select("SELECT switch_panel.ID FROM switch_panel,system_user_has_switch_panel WHERE system_user_has_switch_panel.SYSTEM_USER_ID = #{id} AND system_user_has_switch_panel.SWITCH_PANEL_ID = switch_panel.ID")
	@ResultMap(value="MiniResultMapOfSwitchPanel")
	List<SwitchPanel> findSwitchPanelBYSystemUserID(@Param("id") String id );

}